import { createStore } from 'vuex'

export default createStore({
  state: {
    _token: window.localStorage.getItem("_token") ?
    window.localStorage.getItem("_token") : "",
    userId:window.localStorage.getItem("userId") ?
    window.localStorage.getItem("userId") : "",
    Name:window.localStorage.getItem("Name") ?
    window.localStorage.getItem("Name") : ""
  },
  getters: {
  },
  mutations: {
     // 更新 token 信息
     updateToken(state, _token) {
      localStorage.setItem("_token", _token);
      state._token = _token;
    },
    // 更新 userId 信息
    updateUserId(state, id) {
      localStorage.setItem("userId", id);
      state.userId = id;
    },
    // 用户退出
    userLogout(state) {
      state._token = ''
      state.userId = ''
      state.Name = ''
      localStorage.clear()
    },
     // 更新用户名信息
     updateName(state, id) {
      localStorage.setItem("Name", id);
      state.Name = id;
    },
  },
  actions: {
  },
  modules: {
  }
})
